/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package schoolLink;

import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Admin
 */
public class SplashScreen extends Canvas 
{
    private Display     display;
    private Displayable next;
    private Timer       timer = new Timer();
    private Image neoLogo = null;

    public SplashScreen(Display display, Displayable next)
    {
        this.display = display;
        this.next = next;
        ListImage();
        display.setCurrent(this);
    }
    /*
     * 
     */ 
    private void ListImage(){
        try{
            neoLogo = Image.createImage("/img/NeoLogo.png");
            //System.out.println("Image ok!");
        }catch(Exception e){
            System.err.println(e.getMessage());
            //System.out.println("Image error!");
        }
    }
    protected void keyPressed( int keyCode ){
        dismiss();
    }
    /**
     * 
     * @param g 
     */
    protected void paint( Graphics g ){
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, getWidth() , getHeight());
        // do your drawing here
        if (neoLogo!=null) 
          g.drawImage(neoLogo, getWidth() / 2, getHeight() / 2, Graphics.HCENTER|Graphics.VCENTER); 
        //g.drawImage(neoLogo, UP, UP, UP);
    }

    protected void pointerPressed( int x, int y ){
        dismiss();
    }

    protected void showNotify()
    // called automatically when the Canvas is put on screen
    {  timer.schedule( new CountDown(), 2000 );  
               // CountDown started after 5 secs
    }

    private void dismiss(){
        timer.cancel();
        display.setCurrent( next );
    }

    // ----------------------------------------
    private class CountDown extends TimerTask 
    {
        public void run(){
            dismiss();
        }
    }
}